/**
 * Created with IntelliJ IDEA.
 * Description:移动零
 * User: bjc
 * Date: 2025-11-02
 * Time: 21:11
 */
public class Test01_moveZeroes {
    public void moveZeroes(int[] nums) {
        for(int cur = 0,dest = -1;cur<nums.length;cur++){
            if(nums[cur] != 0){
                //交换
                dest++;
                int tmp = nums[dest];
                nums[dest] = nums[cur];
                nums[cur] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        new Test01_moveZeroes().moveZeroes(nums);
        for(int i = 0;i<nums.length;i++){
            System.out.print(nums[i]+" ");
        }
    }
}
